<?php
/*
+------------------------------------------------------------------------------+
|   Rooster - a plugin by Francis Cheung
|
|	Plugin Support Site: e107.webstartinternet.com
|
|	For the e107 website system visit http://e107.org
|
|	Released under the terms and conditions of the
|	GNU General Public License (http://gnu.org).
+------------------------------------------------------------------------------+
*/

// Function declaration
function getDateForSpecificDayBetweenDates($startDate, $weekdayNumber, $numOfWeeks) 
{     
	$startDate = strtotime($startDate);
	$dateArr = array();
	do
	{
		if(date("w", $startDate) != $weekdayNumber)         
		{             
			$startDate += (24 * 3600); // add 1 day         
		}     
	} while(date("w", $startDate) != $weekdayNumber);       
	
	for ($intv=0; $intv < $numOfWeeks; $intv++)
	{         
		$dateArr[] = date('Y-m-d', $startDate);         
		$startDate += (7 * 24 * 3600); // add 7 days     
	}      
	
	return($dateArr); 
} 

function getUserNameForJob($sql, $job_id, $job_date)
{
	if ($sql->db_Select("rooster_tbl","user_id","job_id=".$job_id." AND job_date='".$job_date."'","default"))
	{
		list($str_user_id)=$sql->db_Fetch();
	
		if ($str_user_id == 99)
		{
			if ($sql->db_Select("rooster_tbl","guest_name","job_id=".$job_id." AND job_date='".$job_date."'","default"))
			{
				list($str_user_name)=$sql->db_Fetch();
				return ($str_user_name);
			}
		}
		else 
		{
			if ($sql->db_Select_gen("SELECT u.name FROM ozs_rooster_tbl r inner join ozs_church_user_tbl u
							ON u.id = r.user_id
							WHERE job_id=1 and job_date='".$str_curr_date."'"))
			{
				list($str_user_name)=$sql->db_Fetch();
				return($str_user_name);	
			}	
		}
	}
}
?>
